<?php
// index.php?mod=question&childmod=index&ajax=true&op=
$op = get_get("op");
if ($op == "") {
    returnMessage("-1", "unknownrequest");
    die();
}
if ($op == "qapi") {
    $req = get_entry("req");
    if (! $req)
        api_message("无效的API请求", - 19);
    $qid = get_entry("qid");
    if (! $qid)
        api_message("未找到题目", - 1);
    $question = getQuestion($qid);
    if (! $question)
        api_message("未找到题目", - 1);
    $uid = getSessionUid();

    $setting = array();
    $setting["card"] = getCardInfo($question["uid"]);
    $setting["showauthor"] = get_entry("showauthor") ? true : false;
    $setting["subject"] = getSubjectBySid($question["sid"])["displayname"];
    if ($req == "question") {
        if (! checkPermission($uid, $question, 1, true))
            api_message("拒绝访问", - 2);
        $setting["qid"] = $qid;
        $setting["type"] = "question";
        $setting["data"] = $question["question"];
        setSetting("question_bank_api", $setting);
        loadTemp("questionbank/question_bank_api.php");
        die();
    }
    if ($req == "answer") {
        if (! checkPermission($uid, $question, 2, true))
            api_message("拒绝访问", - 2);
        $setting["qid"] = $qid;
        $setting["type"] = "answer";
        $setting["data"] = array(
            "answer" => $question["answer"],
            "detial" => $question["answer_detial"]
        );
        setSetting("question_bank_api", $setting);
        loadTemp("questionbank/question_bank_api.php");
        die();
    }
    if ($req == "explain") {
        if (! checkPermission($uid, $question, 3, true))
            api_message("拒绝访问", - 2);
        $setting["qid"] = $qid;
        $setting["type"] = "explain";
        $setting["data"] = $question["qexplain"];
        setSetting("question_bank_api", $setting);
        loadTemp("questionbank/question_bank_api.php");
        die();
    }
    api_message("无效的API请求,无效的指令 $req", - 20);
}

if ($op == "createQuestion") {
    if (! is_Teacher(getSessionUid())) {
        printMessage("error", "只有教师可以进入这里");
        die();
    }
    $setting = array();
    $setting["isNew"] = true;
    $setting["subject"] = getTeacherSubject(getSessionUid());
    loadTemp("questionbank/personal_view/question_editor.php");
    die();
}
returnMessage("-1", "未知的请求：$op");
?>